#!/usr/bin/env coffee

import {create} from 'ipfs'
import path from 'path'

do =>
  self = new URL(import.meta.url).pathname
  root = path.dirname path.dirname self

  node = await create {
    repo: path.join(root,'ipfs')
    EXPERIMENTAL:
      pubsub:true
      sharding:true
  }

  ###
  console.log await node.files.write(
    '/hi'
    '测试 IPFS技术教程--干货必看！ : https://t.cn/A6x7VRCV'
    create:true
  )
  ###

  console.log await node.files.flush('/')

  for await i from node.files.ls("/ipfs/QmPiWG1Nhk9NRZSxhmHLkyXLaUx6CeF1ejsJRsX9DixQL2")
    console.log i.name,i.size,i.mode,i.mtime

  for await i from node.files.read("/ipfs/QmPiWG1Nhk9NRZSxhmHLkyXLaUx6CeF1ejsJRsX9DixQL2/hi")
    console.log i.toString 'utf8'
